<?php 
  $colname_rs_upsetting = $_GET['itemid'];
$rs_upsetting = getPageSettingsDetails($colname_rs_upsetting);
$row_rs_upsetting = mysql_fetch_assoc($rs_upsetting);
$totalRows_rs_upsetting = mysql_num_rows($rs_upsetting);
?>

<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="14%">Setting Name </td>
    <td width="86%">&nbsp;</td>
  </tr>
  <tr>
    <td>Setting Value </td>
    <?php 
	//Banner
	if($row_rs_upsetting['setting_name']=="CURRENTBANNER"){?>
		<td> <?php 
                            $rs_resources1 =getSiteBanners();
                            $row_rs_resources1 = mysql_fetch_assoc($rs_resources1);
                            $totalRows_rs_resources1 = mysql_num_rows($rs_resources1);

                            ?>

                            <?php do { ?>

                            <input type="radio" name="settingvalue" value="<?php echo  $row_rs_resources1["resource_id"]; ?>" id="grp_<?php echo  $row_rs_resources1["resource_id"]; ?>" <?php if($row_rs_resources1["resource_id"] ==$row_rs_upsetting['setting_value']) echo "checked='checked'";?>  />
                            <a href="../resources/<?php echo $row_rs_resources1['resource_url']; ?>" rel="facebox" >
                                <img name="" src="../resources/thump.php?im=<?php echo  $row_rs_resources1["resource_url"]; ?>" alt="" /></a>
                                <?php }while($row_rs_resources1 = mysql_fetch_assoc($rs_resources1));?>
                            <input type="radio" name="settingvalue" value="" />None
		</td>
	<?php } 
	//Image Processing
	else if(strEndsWith(strtolower($row_rs_upsetting['setting_name']),"pix,image,logo,picture,img,image")) { ?>
		<td><?php $resourceDetails = getResourceDetails($row_rs_upsetting['setting_value']); $res = mysql_fetch_assoc($resourceDetails); ?>
		 <input type="radio" name="settingvalue" value="<?php echo  $row_rs_upsetting['setting_value']; ?>" />
		  <a href="../resources/<?php echo $res['resource_url']; ?>" rel="facebox" >
                                <img name="" src="../resources/thump.php?im=<?php echo  $res["resource_url"]; ?>" alt="" />
		  </a>
		  Search New Image <input type="text"  onclick="getData('pages/image_radio.php?r=settingvalue&q='+this.value,'rdiv')" />
		  <div id="rdiv"></div>
		</td>
	<?php } 
	//yes No Option
	else if(checkYesNo($row_rs_upsetting['setting_value'])) { ?>
		<td><?php echo buildYesNo($row_rs_upsetting['setting_value'],'settingvalue'); ?></td>
	<?php }
	//Default Site
	else if(($row_rs_upsetting['setting_name']=="DEFAULT_SITE")){?>
		<td>
	<select name="settingvalue">	
		<?php 
	  $rs_s = getCategoryByParent(38);
	$sites = mysql_fetch_assoc($rs_s);
	do{
	?><option value="<?php echo $sites["category_id"]?>" <?php if($sites["category_id"]==$row_rs_upsetting['setting_value'] ) echo "selected='selected'"; ?>><?php echo $sites["category_name"]?></option>
	<?php }while($sites = mysql_fetch_assoc($rs_s)); mysql_free_result($rs_s); ?>
	</select>
	</td>
	<?php
	}else{
	 ?>	
	  <td><textarea name="settingvalue" cols="50" rows="3"><?php echo htmlentities($row_rs_upsetting['setting_value'], ENT_COMPAT, 'utf-8'); ?></textarea> </td>
<?php } ?>
  </tr>
</table>
<tr valign="baseline">
      <td nowrap="nowrap" align="center"></td>
      <td><input type="submit" value="Update record" /></td>
    </tr>
  </table>
  <input type="hidden" name="MM_update" value="frmeditsetting" />
  <input type="hidden" name="settingname" value="<?php echo $row_rs_upsetting['setting_name']; ?>" />
</form>

<?php
mysql_free_result($rs_upsetting);
function buildYesNo($selected,$name){
	$yesNo = array("Yes","No");
	for($i=0;$i<count($yesNo);$i++){
	$str.="<input type='radio' name='$name'  value='".strtolower($yesNo[$i])."'";
   if(strtolower($selected) == strtolower($yesNo[$i]))
   $str.=" checked='checked '";
	$str.="> ".$yesNo[$i];
	}
	return $str;
}
function checkYesNo($val){
	$val = strtolower($val);
	if($val=="yes" || $val=="no")
	return true;
	
	return false;
}

function strEndsWith($haysack,$needle){
$needles = split(",",$needle);
for($i=0;$i<count($needles);$i++){
 if(strrpos($haysack,$needles[$i]) + strlen($needles[$i]) == strlen($haysack))
  return true;
 }
  return false;

}


?>
